<template>
  <el-dialog
    title="编辑员工信息"
    :visible.sync="visible"
    width="30%"
    @close="resetForm"
  >
    <el-form :model="form" label-width="80px" ref="form">
      <el-form-item label="员工姓名" prop="name">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="账号" prop="username">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-switch v-model="form.status" active-text="启用" inactive-text="禁用"></el-switch>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="submitForm">保存</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {

  data() {
    return {
      visible: false,
      form: {
        id: null,
        name: "",
        username: "",
        phone: "",
        status: true,
      },
    };
  },

  methods: {
    open(row) {
      this.form = { ...row }; // 将当前行的数据填充到表单中
      this.visible = true;
    },
    resetForm() {
      this.$refs.form.resetFields(); // 重置表单
    },
    submitForm() {
      this.$emit("submit", this.form); // 提交表单数据
      this.visible = false;
    },
  },
};
</script>